package com.gzhryc.common.gps;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class MemoryGPSDataService implements IGPSDataService{

    ConcurrentHashMap<Long,GPSEntity> gpsMap;

    public MemoryGPSDataService(){
        this.gpsMap = new ConcurrentHashMap<>();
    }

    public GPSEntity getById(Long id){
        if(id != null) {
            return this.gpsMap.get(id);
        }
        return null;
    }

    public void save(GPSEntity gpsEntity){
        this.gpsMap.put(gpsEntity.getId(),gpsEntity);
    }

    public void remove(Long id){
        if(id != null) {
            this.gpsMap.remove(id);
        }
    }

    public List<GPSEntity> getList(){
        return new ArrayList<>(this.gpsMap.values());
    }

    @Override
    public Integer getSize() {
        return this.gpsMap.size();
    }
}
